package sync

import (
	"api/app/auth/auto/v1/mc"
	"api/app/auth/models"
	"api/app/auth/service"
	"api/libs/errs"
	modelsync "api/public/model-sync"
	"context"
	"gitee.com/dreamwood/ez"
)

func init() {
	modelsync.GetMS().ListenToInitNeed("Department", func(in *modelsync.InitNeed) {
		//这里切忌，1.不要一次性发送过多的数据
		//2.不要发送过大的，比如包含富文本的
		//3实在不行可以发送接口地址，再自行获取数据
		//service.DoThePublishAction()
		service.DealWithDepartmentInitFeed(in)
	})
	ez.ListenJoin(mc.DepartmentEventAfterSave, func(v interface{}, ctx context.Context) {
		model, ok := v.(*models.Department)
		if ok {
			errs.Try(modelsync.GetMS().PubCrudUpdate("Department", model))
		}
	})
	ez.ListenJoin(mc.DepartmentEventDelete, func(v interface{}, ctx context.Context) {
		ez.JsonLog(v)
		model, ok := v.(*models.Department)
		if ok {
			errs.Try(modelsync.GetMS().PubCrudDelete("Department", model))
		}
	})
}
